<template>
    <el-dialog v-model="dialogFormVisible" :title="form.address.id ? '编辑地址' : '添加地址'" width="500">
        <el-form :model="form">
            <itemInput label="所属用户" v-model="form.user_name" append="用户名" :disabled="form.address.id > 0"/>
            <itemInput label="姓名" v-model="form.address.name"/>
            <itemInput label="手机/电话" v-model="form.address.phone"/>
            <itemCity label="省市区" 
                v-model:province="form.address.provinces_codes" 
                v-model:provinceName="form.address.provinces"
                v-model:city="form.address.city_codes"
                v-model:cityName="form.address.city"
                v-model:area="form.address.area_codes"
                v-model:areaName="form.address.area"/>
            <itemInput label="详细地址" v-model="form.address.address"/>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="submits">提交</el-button>
            </div>
        </template>
    </el-dialog>
</template>
<script>
import itemInput from '@/components/form/item.input.vue'
import itemCity from '@/components/form/item.city.vue'
export default {
    emit: ['refresh'],
    data() {
        return {
            formLabelWidth: '120px',
            dialogFormVisible: false,
            form: {
                address:{}
            }
        }
    },
    methods:{
        // 打开弹窗显示
        Open(res={}){
            this.form = JSON.parse(JSON.stringify(res));
            if(!this.form.address){
                this.form.address = {}
            }
            this.dialogFormVisible = true;
        },
        // 提交表单
        submits(){
            var that = this
            that.$http.post("/admin/user/address/create",that.form).then(()=>{
                that.$func.success("提交成功")
                that.dialogFormVisible = false
                that.$emit('refresh')
            })
        }
    },
    components: {
        itemInput,
        itemCity,
    },
}
</script>